import { Injectable } from '@nestjs/common';
import axios from 'axios';

@Injectable()
export class WhisperService {
  private readonly openaiApiKey: string;

  constructor() {
    this.openaiApiKey = 'xxx';
  }

  async transcribeAudio(audioBuffer: Buffer): Promise<string> {
    const response = await axios.post(
      'https://api.openai.com/v1/audio/transcriptions',
      audioBuffer,
      {
        headers: {
          'Content-type': 'audio/webm',
          Authorization: `Bearer ${this.openaiApiKey}`,
        },
      },
    );
    return response.data.text;
  }
}
